package com.whnk.web.controller.rtms;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.whnk.common.annotation.Log;
import com.whnk.common.base.AjaxResult;
import com.whnk.common.enums.BusinessType;
import com.whnk.framework.web.base.BaseController;
import com.whnk.framework.web.page.TableDataInfo;
import com.whnk.rtms.domain.DevVersionContrl;
import com.whnk.rtms.service.IDevVersionContrlService;

/**
 * 版本开发流管理 信息操作处理
 * 
 * @author whwhnk
 * @date 2019-03-26
 */
@Controller
@RequestMapping("/rtms/devVersionContrl")
public class DevVersionContrlController extends BaseController
{
    private String prefix = "rtms/devVersionContrl";
	
	@Autowired
	private IDevVersionContrlService devVersionContrlService;
	
	@RequiresPermissions("rtms:devVersionContrl:view")
	@GetMapping()
	public String devVersionContrl()
	{
	    return prefix + "/devVersionContrl";
	}
	
	/**
	 * 查询版本开发流管理列表
	 */
	@RequiresPermissions("rtms:devVersionContrl:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(DevVersionContrl devVersionContrl)
	{
		startPage();
        List<DevVersionContrl> list = devVersionContrlService.selectDevVersionContrlList(devVersionContrl);
		return getDataTable(list);
	}
	
	/**
	 * 查询所有的开发流
	 */
	@RequiresPermissions("rtms:devVersionContrl:list")
	@PostMapping("/diffDevStream")
	@ResponseBody
	public List<DevVersionContrl> queryDevStream(){
		return devVersionContrlService.selectDevStream();
	}
	
	
	/**
	 * @return 查询唯一项目名
	 */
	@RequiresPermissions("rtms:devVersionContrl:list")
	@PostMapping("/diffPvobName")
	@ResponseBody
	public List<String> queryPvobName(){
		List<String> result = new ArrayList<String>();
		result = devVersionContrlService.selectPvobName();
		return result;
	}
	/**
	 * 新增版本开发流管理
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存版本开发流管理
	 */
	@RequiresPermissions("rtms:devVersionContrl:add")
	@Log(title = "版本开发流管理", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(DevVersionContrl devVersionContrl)
	{	
		//
		Date date = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmssS");
		devVersionContrl.setDevVersionId(dateFormat.format(date));
		devVersionContrl.setCreateTime(date);
		devVersionContrl.setLastUpdateTime(date);
		return toAjax(devVersionContrlService.insertDevVersionContrl(devVersionContrl));
	}

	/**
	 * 修改版本开发流管理
	 */
	@GetMapping("/edit/{devVersionId}")
	public String edit(@PathVariable("devVersionId") String devVersionId, ModelMap mmap)
	{
		DevVersionContrl devVersionContrl = devVersionContrlService.selectDevVersionContrlById(devVersionId);
		mmap.put("devVersionContrl", devVersionContrl);
	    return prefix + "/edit";
	}
	
	/**
	 * 生成基线
	 */
	@GetMapping("/genbaseline")
	public String genBaseLine(){
		return prefix + "/genbaseline";
	}
	
	/**
	 * 修改保存版本开发流管理
	 */
	@RequiresPermissions("rtms:devVersionContrl:edit")
	@Log(title = "版本开发流管理", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(DevVersionContrl devVersionContrl)
	{		
		return toAjax(devVersionContrlService.updateDevVersionContrl(devVersionContrl));
	}
	
	/**
	 * 删除版本开发流管理
	 */
	@RequiresPermissions("rtms:devVersionContrl:remove")
	@Log(title = "版本开发流管理", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(devVersionContrlService.deleteDevVersionContrlByIds(ids));
	}
	
}
